namespace C1.Win.C1FlexGrid.Util.BaseControls
{
    using System;
    using System.Windows.Forms;

    public abstract class MaskedComboBox : ComboBox
    {
        private InputMask _mask;

        public MaskedComboBox()
        {
            this._mask = new InputMask(this);
        }

        public int EditPosition(int index)
        {
            return this._mask.EditPosition(index);
        }

        public string GetValidContent()
        {
            string validContent = this._mask.GetValidContent();
            if (validContent != null)
            {
                return validContent;
            }
            return this.Text;
        }

        protected bool IsCombo()
        {
            return false;
        }

        protected bool IsUpdating()
        {
            return this._mask.IsUpdating();
        }

        public bool IsValid()
        {
            return (this._mask.GetValidContent() != null);
        }

        protected override void OnKeyDown(KeyEventArgs e)
        {
            base.OnKeyDown(e);
        }

        protected override void OnKeyPress(KeyPressEventArgs e)
        {
            if (!this.IsCombo() || this._mask.OnKeyPress(e))
            {
                base.OnKeyPress(e);
            }
        }

        protected override void OnTextChanged(EventArgs e)
        {
            if (!this.IsCombo() || this._mask.OnTextChanged(e))
            {
                base.OnTextChanged(e);
            }
        }

        public string Content
        {
            get
            {
                return this._mask.GetContent();
            }
        }

        public string Mask
        {
            get
            {
                return this._mask.Mask;
            }
            set
            {
                this._mask.Mask = value;
                this.OnTextChanged(null);
            }
        }

        public char PlaceHolder
        {
            get
            {
                return this._mask.PlaceHolder;
            }
            set
            {
                this._mask.PlaceHolder = value;
                this.OnTextChanged(null);
            }
        }
    }
}

